package com.taoxi.good.controller;

import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.core.page.TableDataInfo;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.good.domain.GoodWholesaler;
import com.taoxi.good.service.IGoodWholesalerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 批发商商品Controller
 *
 * @author ruoyi
 * @date 2024-10-24
 */
@Api(tags = "批发商商品Controller")
@RestController
@RequestMapping("/good/wholesalergood")
public class GoodWholesalerController extends BaseController {
    @Autowired
    private IGoodWholesalerService goodWholesalerService;

    /**
     * 查询批发商商品列表
     */
    @ApiOperation("查询批发商商品列表")
    @PreAuthorize("@ss.hasPermi('good:wholesalergood:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodWholesaler goodWholesaler) {
        startPage();
        List<GoodWholesaler> list = goodWholesalerService.selectGoodWholesalerList(goodWholesaler);
        return getDataTable(list);
    }

    /**
     * 导出批发商商品列表
     */
    @ApiOperation("导出批发商商品列表")
    @PreAuthorize("@ss.hasPermi('good:wholesalergood:export')")
    @Log(title = "批发商商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodWholesaler goodWholesaler) {
        List<GoodWholesaler> list = goodWholesalerService.selectGoodWholesalerList(goodWholesaler);
        ExcelUtil<GoodWholesaler> util = new ExcelUtil<GoodWholesaler>(GoodWholesaler.class);
        util.exportExcel(response, list, "批发商商品数据");
    }

    /**
     * 获取批发商商品详细信息
     */
    @ApiOperation("获取批发商商品详细信息")
    @PreAuthorize("@ss.hasPermi('good:wholesalergood:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodWholesalerService.selectGoodWholesalerById(id));
    }

    /**
     * 新增批发商商品
     */
    @ApiOperation("新增批发商商品")
    @PreAuthorize("@ss.hasPermi('good:wholesalergood:add')")
    @Log(title = "批发商商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodWholesaler goodWholesaler) {
        return toAjax(goodWholesalerService.insertGoodWholesaler(goodWholesaler));
    }

    /**
     * 修改批发商商品
     */
    @ApiOperation("修改批发商商品")
    @PreAuthorize("@ss.hasPermi('good:wholesalergood:edit')")
    @Log(title = "批发商商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodWholesaler goodWholesaler) {
        return toAjax(goodWholesalerService.updateGoodWholesaler(goodWholesaler));
    }

    /**
     * 删除批发商商品
     */
    @ApiOperation("删除批发商商品")
    @PreAuthorize("@ss.hasPermi('good:wholesalergood:remove')")
    @Log(title = "批发商商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodWholesalerService.deleteGoodWholesalerByIds(ids));
    }
}
